package br.com.fatecpg.entreamigosapp;


import com.example.entreamigosapp.R;
import com.example.entreamigoslocal.NovoEventoActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {
	
	 //private EditText usuario,senha;
	   public static final String MyPREFERENCES = "MyPrefs" ;
	   public static final String name = "nameKey"; 
	   public static final String pass = "passwordKey"; 
	   SharedPreferences sharedpreferences;

	   private EditText username = (EditText)findViewById(R.id.usuario);
	   private EditText password = (EditText)findViewById(R.id.senha);


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//EditText username = (EditText)findViewById(R.id.usuario);
				//EditText password = (EditText)findViewById(R.id.senha);
				
				 sharedpreferences=getSharedPreferences(MyPREFERENCES, 
					      Context.MODE_PRIVATE);
					      if (sharedpreferences.contains(name))
					      {
					      if(sharedpreferences.contains(pass)){
					         Intent i = new Intent(this,NovoEventoActivity.class);
					         startActivity(i);
					      }}
			
	}
	
	 /*
	  * onResume
	  * sharedpreferences=getSharedPreferences(MyPREFERENCES, 
    Context.MODE_PRIVATE);
    if (sharedpreferences.contains(name))
    {
    if(sharedpreferences.contains(pass)){
       Intent i = new Intent(this,NovoEventoActivity.class);
       startActivity(i);
    }
    }*/
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	 public void login(View view){
	      Editor editor = sharedpreferences.edit();
	      String u = username.getText().toString();
	      String p = password.getText().toString();
	      editor.putString(name, u);
	      editor.putString(pass, p);
	      editor.commit();
	      
	      Intent i = new Intent(this,NovoEventoActivity.class);
	      startActivity(i);
	   }

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
